﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArraysAndStrings.FindMaxConsecutiveOnes
{
    class MainProject
    {
        static void Main(string[] args)
        {
            int[] nums = new int[] { 0,1};
            Console.WriteLine(FindMaxConsecutiveOnes(nums));
            Console.ReadKey();
        }
        public static int FindMaxConsecutiveOnes(int[] nums)
        {
            int preIndex = 0;
            int nextIndex = 0;
            int max = 0;
            while (preIndex< nums.Length)
            {
                if (nums[preIndex] == 1)
                {
                    nextIndex = preIndex;
                    nextIndex++;
                    if (nextIndex < nums.Length)
                    {
                        while (nums[nextIndex] == 1)
                        {
                            nextIndex++;
                            if (nextIndex >= nums.Length) break;

                        }
                    }
                    max = Math.Max((nextIndex - preIndex) , max);
                    preIndex = nextIndex ;
                }
                preIndex++;
                if (preIndex >= nums.Length) break;
            }
            return max;
        }
    }
}
